package com.dhc.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhc.service.entity.AdminLogin;
import com.dhc.service.entity.dto.AdminRegisterDto;
import com.dhc.service.entity.vo.AdminLoginVo;
import com.dhc.service.mapper.AdminLoginMapper;
import com.dhc.service.service.AdminLoginService;
import lombok.NonNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description 针对表【ADMIN_LOGIN(管理员登录表)】的数据库操作Service实现
 * @createDate 2023-10-07 18:49:57
 */
@Service
public class AdminLoginServiceImpl extends ServiceImpl<AdminLoginMapper, AdminLogin>
		implements AdminLoginService {

	@Autowired
	private AdminLoginMapper adminLoginMapper;

	@Override
	public AdminLogin login(@NonNull String adminUsername, @NonNull String adminPassword) {
		QueryWrapper<AdminLogin> wrapper = new QueryWrapper<>();
		wrapper.eq("ADMIN_USERNAME", adminUsername);
		wrapper.eq("ADMIN_PASSWORD", adminPassword);
		return adminLoginMapper.selectOne(wrapper);
	}

	@Override
	public AdminLogin register(@NonNull AdminRegisterDto adminRegisterDto) {
//		String uuid = UUID.randomUUID().toString();
		AdminLogin adminLogin = new AdminLogin();
		adminLogin.setAdminUsername(adminRegisterDto.getUsername());
		adminLogin.setAdminPassword(adminRegisterDto.getPassword());
		adminLogin.setAdminEmail(adminRegisterDto.getEmail());
		int insert = adminLoginMapper.insert(adminLogin);
		if (insert == 0) {
			return null;
		}
		QueryWrapper<AdminLogin> wrapper = new QueryWrapper<>();
		wrapper.eq("ADMIN_USERNAME", adminRegisterDto.getUsername());
		wrapper.eq("ADMIN_PASSWORD", adminRegisterDto.getPassword());
		return adminLoginMapper.selectOne(wrapper);
	}
}




